<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
    
        //构造函数
        function Person(name) {
            this.name = name;
        }
        //为构造函数的原型对象添加 继承方法
        Person.prototype.extend = function(obj) {
            //将传入的 obj对象的属性和方法 继承给 实例对象
            for(var k in obj) {
                this[k] = obj[k];
            }
        }
    
        //实例化对象
        var p1 = new Person('jack');

        var p2 = {age:18,sex:'男'};

        //p1想 继承p2的属性和方法
        p1.extend(p2);

        console.log(p1);
        
    </script>
</body>
</html>